'use strict';

module.exports = function(sequelize, DataTypes) {
    const pointRule = sequelize.define('pointRule', {
        id: {
            type: DataTypes.BIGINT(20).UNSIGNED,
            allowNull: false,
            autoIncrement: true,
            primaryKey: true,
            readonly: true
        },
        type_id: {
            type: DataTypes.BIGINT(20).UNSIGNED,
            allowNull: false,
            comment: '规则类型'
        },
        name: {
            type: DataTypes.STRING(191),
            allowNull: false,
            comment: '规则名称'
        },
        title: {
            type: DataTypes.STRING(191),
            allowNull: false,
            comment: '规则说明'
        },
        alteration: {
            type: DataTypes.FLOAT.UNSIGNED,
            defaultValue: 0,
            comment: '积分变动, 都为正数'
        },
        //coefficient: {  //弃用, 没啥用
        //    type: DataTypes.FLOAT.UNSIGNED,
        //    defaultValue: 0,
        //    comment: '惩罚系数,只有修改和申诉时候有用'
        //},
        //coefficientType: {
        //    type: DataTypes.ENUM,
        //    values: ['add', 'multiply'],
        //    defaultValue: 'add',
        //    comment: '惩罚系数的处理方式,主要区分做减法还是做乘法'
        //},
        start_time: {
            type: DataTypes.DATE,
            comment: '预留字段, 时效性的积分规则'
        },
        end_time: {
            type: DataTypes.DATE,
            comment: '预留字段,时效性的积分规则'
        },
        is_valid: {
            type: DataTypes.BOOLEAN,
            allowNull: false,
            defaultValue: 0
        },
        created_by: {
            type: DataTypes.BIGINT(20).UNSIGNED,
            readonly: true
        },
        updated_by: {
            type: DataTypes.BIGINT(20).UNSIGNED,
        },
        created_at: {
            type: DataTypes.DATE,
            allowNull: false,
            defaultValue: DataTypes.NOW,
            readonly: true
        },
        updated_at: {
            type: DataTypes.DATE,
            allowNull: false,
            defaultValue: DataTypes.NOW,
        }
    }, {
        tableName: 'sophic_point_rules',
        underscored: true,

        indexes: [{
            fields: ['name'],
            unique: true
        },{
            fields: ['type_id']
        }],

        classMethods: {

            operationLog: true,

            associate: function(models) {

            }
        }
    });

    return pointRule;
};